<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "good".
 *
 * @property int $id
 * @property int $cate_id 分类id
 * @property string $name 商品名称
 * @property string $img 商品封面
 * @property string $imgs 商品图片
 * @property int $sale_count 商品销量
 * @property int $store 商品库存
 * @property string $price 商品价格
 * @property string $price_dis 商品优惠价
 * @property string $desc 商品简介
 * @property string $detail_info 商品详情
 * @property int $status 状态
 * @property int $sort 状态
 * @property int $created_at 创建时间
 */
class Good extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'good';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['cate_id', 'sale_count', 'sort', 'store', 'status', 'created_at'], 'integer'],
            [['price', 'price_dis'], 'number'],
            [['desc', 'detail_info', 'imgs'], 'string'],
            [['name', 'img'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cate_id' => 'Cate ID',
            'name' => 'Name',
            'img' => 'Img',
            'img' => 'Imgs',
            'sale_count' => 'Sale Count',
            'store' => 'Store',
            'price' => 'Price',
            'price_dis' => 'Price Dis',
            'desc' => 'Desc',
            'detail_info' => 'Detail Info',
            'sort' => 'Sort',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getCate(){
      return $this->hasOne(GoodCate::class, ['id' => 'cate_id']);
    }
}
